﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace SilverlightDebateViewModel.Classes
{
    public class TwoValuesProgressBar : ProgressBar, INotifyPropertyChanged
    {

        public TwoValuesProgressBar() : base()
        {
        }

        public static readonly DependencyProperty Value1Property =
             DependencyProperty.Register("Value1",
                                             typeof(int),
                                             typeof(TwoValuesProgressBar),
                                             new PropertyMetadata(0,
                                                                     new PropertyChangedCallback(OnValue1Changed)));
        public static readonly DependencyProperty Value2Property =
             DependencyProperty.Register("Value2",
                                             typeof(int),
                                             typeof(TwoValuesProgressBar),
                                             new PropertyMetadata(0,
                                                                     new PropertyChangedCallback(OnValue2Changed)));



        public int Value1
        {
            get { return (int)base.GetValue(Value1Property); }
            set { base.SetValue(Value1Property, value); SetMaximum(); }
        }

        public int Value2
        {
            get { return (int)base.GetValue(Value2Property); }
            set { base.SetValue(Value2Property, value); SetMaximum(); }
        }



        public static void OnValue1Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TwoValuesProgressBar bar = d as TwoValuesProgressBar;
            bar.Maximum = bar.Value1 + bar.Value2;
        }

        public static void OnValue2Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TwoValuesProgressBar bar = d as TwoValuesProgressBar;
            bar.Maximum = bar.Value1 + bar.Value2;
        }

        //public void OnValue2Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        //{
        //    SetMaximum();
        //}

        private void SetMaximum()
        {
            this.Maximum = Value1 + Value2;
        }


        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion


    }
}
